package cn.nbt.busManage.model.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Data
@EqualsAndHashCode(callSuper = true)
@Table(name="bus_user")
public class User extends BaseEntity{
    @Column(name = "user_name")
    private String userName;
    @ManyToMany(cascade = CascadeType.PERSIST)
    @JoinTable(name = "bus_user_role",
            joinColumns = @JoinColumn(name = "User_id"),
            inverseJoinColumns = @JoinColumn(name = "roles_id"))
    private List<Role> roles;
    @Column(name = "password")
    private String password;
    @Column(name = "email")
    private String email;
    @Column(name = "phone")
    private String phone;
    @Column(name = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;
    @Column(name = "update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public void addRole(Role role) {
        ArrayList<Role> arrayList = new ArrayList<>();
        if (this.roles == null) {
            this.roles = arrayList;
        }
        this.roles.add(role);
    }

}
